﻿using JulMar.Windows.Extensions;
using MediaBrowser.Gui.Design;
using MediaBrowser.IRepository;
using MediaBrowser.IServices;
using MediaBrowser.Services;
using Microsoft.Practices.Unity;
using MediaBrowser.Repository;

namespace MediaBrowser.Gui.ViewModels
{
    /// <summary>
    /// Classe d'initialisation de de classes repository, services, ViewModel
    /// </summary>
    public class ViewModelLocator
    {
        public static IUnityContainer Container
        {
            get;
            private set;
        }

        static ViewModelLocator()
        {
            Container = new UnityContainer();
            if (Designer.InDesignMode)
            {
                Container.RegisterType<IMediaRepository, FakeMediaRepository>()
                    .RegisterType<IMediaManager, MediaManager>();
            }
            else
            {
                Container.RegisterType<IMediaRepository, XmlMediaRepository>()
                    .RegisterType<IMediaManager, MediaManager>();
            }

            Container.RegisterType<PageHomeViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<PageMoviesViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<PageMusicViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<PagePicturesViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<PageBooksViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<MainViewModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ViewModelAbout>(new ContainerControlledLifetimeManager());
            Container.RegisterType<SplashScreenMBViewModel>(new ContainerControlledLifetimeManager());
        }

        #region ViewModels

        public MainViewModel Main
        {
            get
            {
                return Container.Resolve<MainViewModel>();
            }
        }

        public PageHomeViewModel Home
        {
            get
            {
                return Container.Resolve<PageHomeViewModel>();
            }
        }

        public PageMoviesViewModel Movies
        {
            get
            {
                return Container.Resolve<PageMoviesViewModel>();
            }
        }

        public PageMusicViewModel Musics
        {
            get
            {
                return Container.Resolve<PageMusicViewModel>();
            }
        }

        public PagePicturesViewModel Pictures
        {
            get
            {
                return Container.Resolve<PagePicturesViewModel>();
            }
        }

        public PageBooksViewModel Books
        {
            get
            {
                return Container.Resolve<PageBooksViewModel>();
            }
        }

        public ViewModelAbout About
        {
            get
            {
                return Container.Resolve<ViewModelAbout>();
            }
        }

        public SplashScreenMBViewModel SplashScreenMB
        {
            get
            {
                return Container.Resolve<SplashScreenMBViewModel>();
            }
        }

        

        #endregion
    }
}
